package com.samapp.indent;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.samapp.R;
import com.samapp.entity.IndentDetail;

public class IndentDetailAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<IndentDetail> mIndentDetails;

	public IndentDetailAdapter(Context context, List<IndentDetail> mIndentDetails) {
		this.mInflater = LayoutInflater.from(context);
		this.mIndentDetails = mIndentDetails;
	}

	@Override
	public int getCount() {
		return mIndentDetails.size();
	}

	@Override
	public Object getItem(int position) {
		return mIndentDetails.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.indent_detail_item, parent, false);
			holder = new ViewHolder();
			holder.detectionItem = (TextView) convertView.findViewById(R.id.detection_item);
			holder.detectionMethod = (TextView) convertView.findViewById(R.id.detection_method);
			holder.price = (TextView) convertView.findViewById(R.id.price);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		IndentDetail mIndentDetail = mIndentDetails.get(position);
		holder.detectionItem.setText(mIndentDetail.getTestItemId());
		holder.detectionMethod.setText(mIndentDetail.getTestMethodId());
		holder.price.setText(mIndentDetail.getActualPrice());
		return convertView;
	}

	private class ViewHolder {
		TextView detectionItem;
		TextView detectionMethod;
		TextView price;
	}
}
